package wli.web.util;

import java.io.*;

public class MyCopyFile {
    private File fin  = null;
    private File fout = null;

    public String setFiles(File in, File out) {
	if(!in.isFile()) {
	    return "File "+in.getPath()+" not found.";
	}
	if(out.isFile()) {
	    return "File "+out.getPath()+" exists.";
	}

	fin  = in;
	fout = out;
	return null;
    }

    public String copy() {
	try {
	    FileInputStream fis  = new FileInputStream(fin);
	    FileOutputStream fos = new FileOutputStream(fout);
	    byte[] buf = new byte[1024*8];
	    int i = 0;
	    while((i=fis.read(buf))!= -1) {
		fos.write(buf, 0, i);
	    }
	    fis.close();
	    fos.close();
	}
	catch (Exception e) {
	    return "Copy file error.";
	}
	return null;
    }
}
